package edu.sctu.xiangkun.day201506.day20150608;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.List;

/**
 * Created by user21 on 2015/6/9.
 */
public class DtailUtil {
    private String weijin = "打火机";
    private SetTrianData settriandata;
    private SetPeopleData people;

    /**
     * 构造函数
     */
    public DtailUtil(){
        settriandata = new SetTrianData();
        people = new SetPeopleData();
    }

    /**
     * 获取乘客
     */
    public void getPeople(){
        List<PeopleAppbean> list = people.setPeopleData();
        for(PeopleAppbean people : list){
            if(people.isIs_card()){
                String problem = chaBaoGuo(people);
                System.out.println(problem);
                if(problem.contains("无")){
                    kouPrice(people);
                }
            }else{
                System.out.println("您可能携带有违禁物，请留下来配合我们检查！");
            }
        }
    }

    /**
     * 判断包裹
     * @param people
     * @return
     */
    public String chaBaoGuo(PeopleAppbean people){
        BaoGuoDeth baoguodeth = new BaoGuoDeth(people,weijin);
        if(baoguodeth.chaBaoGuo()){
            return "包裹有问题";
        }else{
            return chaWater(people);
        }
    }

    /**
     * 判断水是否有问题
     * @param people
     * @return
     */
    public String chaWater(PeopleAppbean people) {
        BaoGuoDeth baoguodeth = new BaoGuoDeth(people, weijin);
        if (baoguodeth.chaWater()) {
            return "水有问题";
        } else {
            System.out.println("都无问题");
            ifPrice(people);
            kouPrice(people);
            return "都无问题";
        }
    }

    /**
     * 判断金额
     * @param people
     */
    public void ifPrice(PeopleAppbean people){
        if(people.getPice() > 2){
            System.out.println("进站");

            Calendar calendar = Calendar.getInstance();
            DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG);
            System.out.println("进站时间："+dateFormat.format(calendar.getTime()));

        }else{
            new CardDeth().setPrice(10,people);
            System.out.println("充值完成");
            ifPrice(people);
        }
    }

    public void kouPrice(PeopleAppbean people){
        CardDeth cardeth = new CardDeth(settriandata.setHashMapData());
        if(people.getPice() >= cardeth.getPrice(people.getStart(),people.getEnd())){
            System.out.println("出站，余额为："+ (people.getPice() - cardeth.getPrice(people.getStart(),
                    people.getEnd())));
//            Calendar calendar = Calendar.getInstance();
//            DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG);
//            int i = cardeth.getCount(people.getStart(),people.getEnd());
//            calendar.add(calendar.MINUTE,2*i);
//            System.out.println("出站时间："+dateFormat.format(calendar.getTime()));

        }else{
            cardeth.setPrice(10,people);
            System.out.println("充值成功");
            kouPrice(people);
        }
    }
}
